home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol06 / 04 / pcx2dib / pcx2dib.c < prev    next >
Text File  |  1991-07-01  |  6KB  |  148 lines

  1. /* PCX2DIB.C - Displays a PCX file in Windows 3.0 as a Device-Independent
  2. Bitmap.  Usage:     win pcx2dib <filename>                              */
  3. /* Author: C. Albert Mirho */
  4.  
  5. #include <stdlib.h>
  6. #include <windows.h>
  7. #include "pcx2dib.h"
  8.  
  9. HANDLE hInst;                      // Handle to instance.
  10. HANDLE GhInst;                     // Global Handle to instance.
  11. HWND MainhWnd;                     // Handle to main window.
  12. HDC hMainDC;                       //Handle to display context of main window
  13. char szScreenFile[_MAX_PATH+1];
  14.  
  15. /* Registers the window class */
  16. BOOL BLDInitClass(hInstance)
  17. HANDLE hInstance;
  18. {
  19. WNDCLASS WndClass;
  20.  
  21. /* Fill in the class structure */
  22.     WndClass.style         = 0;
  23.     WndClass.lpfnWndProc   = Pcx2DibWndProc;
  24.     WndClass.cbClsExtra    = 0;
  25.     WndClass.cbWndExtra    = 0;
  26.     WndClass.hInstance     = hInstance;
  27.     WndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  28.     WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  29.     WndClass.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  30.     WndClass.lpszMenuName  = NULL;
  31.     WndClass.lpszClassName = "PCX2DIB";
  32.  
  33.     return RegisterClass(&WndClass);
  34. }
  35.  
  36. /* Create the main window */
  37. HWND BLDInitMainWindow(hInstance)
  38. HANDLE hInstance;
  39. {
  40. HWND hWnd;                  /* window handle                       */
  41. int coordinate[4];          /* Coordinates of main window          */
  42.  
  43.     coordinate[0]=CW_USEDEFAULT;
  44.     coordinate[1]=0;
  45.     coordinate[2]=CW_USEDEFAULT;
  46.     coordinate[3]=0;
  47.  
  48.     hWnd = CreateWindow("PCX2DIB",  /* window class registered earlier  */
  49.            "PCX - DIB Example - Resize the Window!",   /* window caption  */
  50.            WS_OVERLAPPEDWINDOW|WS_THICKFRAME,          /* window style    */
  51.            coordinate[0],          /* x position            */
  52.            coordinate[1],          /* y position            */
  53.            coordinate[2],          /* width                 */
  54.            coordinate[3],          /* height                */
  55.            0,                      /* parent handle         */
  56.            0,                      /* menu or child ID      */
  57.            hInstance,              /* instance              */
  58.            (LPSTR)NULL);           /* additional info       */
  59.  
  60.     return hWnd;
  61. }
  62.  
  63.  
  64. /* Startup code called when application is first run */
  65. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  66. HANDLE hInstance;                 /* current instance                    */
  67. HANDLE hPrevInstance;             /* previous instance                   */
  68. LPSTR lpCmdLine;                  /* command line                        */
  69. int nCmdShow;                     /* show-window type (open/icon)        */
  70. {
  71. MSG msg;                      /* message                             */
  72.  
  73.     hInst = GhInst = hInstance;            /* Saves the current instance               */
  74.  
  75.     if (!hPrevInstance)        /* Is there an other instance of the task   */
  76.         {
  77.         if (!BLDInitClass(hInstance))
  78.             return FALSE;     /* Exits if unable to initialize            */
  79.         }
  80.     /* Check to insure file name was no omitted */
  81.     if (lpCmdLine[0]==0)
  82.     {
  83.         return FALSE;
  84.     } //End if (no file specified)
  85.     lstrcpy ( (LPSTR) szScreenFile, lpCmdLine);
  86.  
  87.     MainhWnd = BLDInitMainWindow(hInstance);
  88.     if (!MainhWnd)           /* Check if the window is created           */
  89.         return FALSE;
  90.  
  91.     ShowWindow(MainhWnd, nCmdShow); /* Show the window                     */
  92.     UpdateWindow(MainhWnd);         /* Send WM_PAINT message to window     */
  93.  
  94.     while (GetMessage(&msg,     /* message structure                        */
  95.         0,                      /* handle of window receiving the message   */
  96.         0,                      /* lowest message to examine                */
  97.         0))                     /* highest message to examine               */
  98.         {
  99.         TranslateMessage(&msg);  /* Translates character keys                */
  100.         DispatchMessage(&msg);   /* Dispatches message to window             */
  101.         }
  102.     return(msg.wParam);          /* Returns the value from PostQuitMessage   */
  103. }
  104.  
  105. /* This procedure displays the PCX file as a DIB  */
  106. /* It re-displays the PCX file every time the WIndow is resized  */
  107. /* or overlapped by another window, by processing the WM_PAINT message */
  108.  
  109. long FAR PASCAL Pcx2DibWndProc(hWnd, message, wParam, lParam)
  110. HWND hWnd;                       /* window handle                            */
  111. unsigned message;                /* type of message                          */
  112. WORD wParam;                     /* additional information                   */
  113. LONG lParam;                     /* additional information                   */
  114. {
  115. PAINTSTRUCT psPS;                           //Paint structure
  116. HDC hDC;                                    //Handle to display context
  117. HCURSOR hOldCursor;                         //Handle to default cursor
  118.  
  119.  
  120.     switch (message)
  121.     {
  122.     case WM_COMMAND:             /* command from application menu     */
  123.         break;
  124.     case WM_SIZE:
  125. /* Mark the entire client area for erasure, when beginpaint is next called */
  126.         InvalidateRect (hWnd, NULL, TRUE);
  127.         break;
  128.     case WM_PAINT:
  129. /* Re-display the PCX file upon receiving a WM_PAINT message */
  130.         hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  131.         hMainDC = BeginPaint(hWnd, &psPS);
  132.         iDisplayPCXFile (szScreenFile);
  133.         EndPaint (hWnd, &psPS);
  134.         SetCursor(hOldCursor);
  135.         break;
  136.     case WM_CREATE:          /* window being created                      */
  137.         break;
  138.     case WM_DESTROY:         /* window being destroyed                   */
  139.         PostQuitMessage(0);
  140.         break;
  141.     default:
  142.         /* Pass on message for default processing */
  143.         return(DefWindowProc(hWnd, message, wParam, lParam));
  144.     }  //End switch (on message)
  145.     return FALSE;        /* Returns FALSE if processed by this WndProc*/
  146. }
  147.  
  148.